﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using NMock2;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Arquitetura.Architectural.Model;
using Arquitetura.Architectural.DataLayer;
using Arquitetura.Architectural.BusinessLogic;
using Arquitetura.Model;
using Arquitetura.DataLayer;
using Arquitetura.BusinessLogic;

namespace Arquitetura.BusinessLogic.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class AlunoProcessUnitTest
    {
        private Mockery mocks;
        private IAlunoData m_mockAlunoData;
        private AlunoProcess m_alunoProcess;

        public AlunoProcessUnitTest()
        {
            mocks = new Mockery();

            m_mockAlunoData = mocks.NewMock<IAlunoData>();
            m_alunoProcess = new AlunoProcess(m_mockAlunoData);
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void TestListarAluno()
        {
            List<Aluno> listaAluno = new List<Aluno>();
            listaAluno.Add
            (
                new Aluno()
                {
                    Id = 1,
                    CPF = "11111111111",
                    RG = "11111111111",
                    Nome = "Pessoa1",
                    Sobrenome = "Pessoa1"
                }
            );

            listaAluno.Add
            (
                new Aluno()
                {
                    Id = 2,
                    CPF = "22222222222",
                    RG = "22222222222",
                    Nome = "Pessoa2",
                    Sobrenome = "Pessoa2"
                }
            );

            listaAluno.Add
            (
                new Aluno()
                {
                    Id = 3,
                    CPF = "33333333333",
                    RG = "33333333333",
                    Nome = "Pessoa3",
                    Sobrenome = "Pessoa3"
                }
            );

            Resultado<IQueryable<Aluno>> resultado = 
                new Resultado<IQueryable<Aluno>>(listaAluno.AsQueryable());

            
            Expect.Once.On(m_mockAlunoData).
                Method("Select").
                WithNoArguments().
                Will(Return.Value(resultado));
            
            var p1 = m_alunoProcess.Listar();

            Assert.AreEqual(3, p1.Retorno.Count());
        }
    }
}
